package com.mdnote.jianzhi_offer.linked_list;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/11/10 18:38
 * @Email rhythm_2019@163.com
 * @Description 剑指 Offer 25. 合并两个排序的链表
 */
public class Offer25 {


    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        // Terminator
        if (l1 == null) {
            return l2;
        }
        if (l2 == null) {
            return l1;
        }

        ListNode cur = null;
        if (l1.val >= l2.val) {
            cur = l2;
            cur.next = mergeTwoLists(l2.next, l1);
        } else {
            cur = l1;
            cur.next = mergeTwoLists(l1.next, l2);
        }

        return cur;
    }

     public static class ListNode {
         int val;
         ListNode next;
         ListNode(int x) { val = x; }
     }
}
